<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>传递参数值时，使用"匿名函数"调用带参数的函数</title>
</head>

<body>
    <p>实例演示了在使用 addEventListener() 方法时如何传递参数。</p>
    <p>点击按钮执行计算。</p>
    <button id="myBtn">点我</button>
    <p id="demo"></p>
    <script>
        var p1 = 5;
        var p2 = 7;
        document.getElementById("myBtn").addEventListener("click", function () {
            myFunction(p1, p2);
        });
        function myFunction(a, b) {
            var result = a * b;
            document.getElementById("demo").innerHTML = result;
        }
    </script>
</body>

</html>